function  [B ] = generatespy9_index(Nx,Ny,  m_ccc,m_css,m_cww,m_cee,m_cnn,m_cne,m_cnw,m_cse, m_csw)
%UNTITLED4 Summary of this function goes here
%   Detailed explanation goes here

% Construct the bigger stencil
B = zeros(Nx*Ny, Nx*Ny);


for ii=2:Nx+1
    for jj= 2:Ny+1
        index = (jj-2)*Nx+(ii-1);
        B(index,index) = m_ccc(jj,ii);
    end
end

%% Inner Points
for ii = 3:Nx
    for jj = 3:Ny
        index = (jj-2)*Nx+(ii-1);
        B(index,index-1)= m_cww(jj,ii);
        B(index,index+1) = m_cee(jj,ii);
        B(index,index+Nx) = m_cnn(jj,ii);
        B(index,index-Nx) = m_css(jj,ii);
    end
end

% The Rotated Stencil points
for ii = 3:Nx
    for jj = 3:Ny
        index = (jj-2)*Nx+(ii-1);
        B(index,index+Nx+1) = m_cne(jj,ii);
        B(index,index+Nx-1) = m_cnw(jj,ii);
        B(index,index-Nx+1) = m_cse(jj,ii);
        B(index,index-Nx-1) = m_csw(jj,ii);
    end
end

%% Boundary Points
for ii = 3:Nx
    % South Boundary
    jj=2;
    index = (jj-2)*Nx+(ii-1);
    B(index,index-1)= m_cww(jj,ii);
    B(index,index+1) = m_cee(jj,ii);
    B(index,index+Nx) = m_cnn(jj,ii);
    B(index,index+Nx+1) = m_cne(jj,ii);
    B(index,index+Nx-1) = m_cnw(jj,ii);
    
    % North Boundary
    jj=Ny+1;
    index = (jj-2)*Nx+(ii-1);
    B(index,index-1)= m_cww(jj,ii);
    B(index,index+1) = m_cee(jj,ii);
    B(index,index-Nx) = m_css(jj,ii);
    B(index,index-Nx+1) = m_cse(jj,ii);
    B(index,index-Nx-1) = m_csw(jj,ii);
    
    
end

for jj = 3:Ny
    
    % West Boundary
    ii=2;
    index = (jj-2)*Nx+(ii-1);
    B(index,index+1) = m_cee(jj,ii);
    B(index,index+Nx) = m_cnn(jj,ii);
    B(index,index-Nx) = m_css(jj,ii);
    B(index,index+Nx+1) = m_cne(jj,ii);
    B(index,index-Nx+1) = m_cse(jj,ii);
    
    
    ii=Nx+1;
    index = (jj-2)*Nx+(ii-1);
    B(index,index-1)= m_cww(jj,ii);
    B(index,index+Nx) = m_cnn(jj,ii);
    B(index,index-Nx) = m_css(jj,ii);
    B(index,index+Nx-1) = m_cnw(jj,ii);
    B(index,index-Nx-1) = m_csw(jj,ii);
    
end

%% -------- Corner Points ---------%%
% South West Corner Point
ii=2;
jj=2;
index = (jj-2)*Nx+(ii-1);
B(index,index+1) = m_cee(jj,ii);
B(index,index+Nx) = m_cnn(jj,ii);
B(index,index+Nx+1) = m_cne(jj,ii);


% North West Corner Point
ii=2;
jj=Ny+1;
index = (jj-2)*Nx+(ii-1);
B(index,index+1) = m_cee(jj,ii);
B(index,index-Nx) = m_css(jj,ii);
B(index,index-Nx+1) = m_cse(jj,ii);


% North East Boundary
ii = Nx+1;
jj = Ny+1;
index = (jj-2)*Nx+(ii-1);
B(index,index-Nx) = m_css(jj,ii);
B(index,index-1)= m_cww(jj,ii);
B(index,index-Nx-1) = m_csw(jj,ii);


% South East Boundary
ii=Nx+1;
jj=2;
index = (jj-2)*Nx+(ii-1);
B(index,index+Nx) = m_cnn(jj,ii);
B(index,index-1)= m_cww(jj,ii);
B(index,index+Nx-1) = m_cnw(jj,ii);


spy(B);
%pause
end

